package com.queclink.ycm.entity.data.useless;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.queclink.ycm.common.utils.HexUtils;
import com.queclink.ycm.entity.data.Data;

import java.text.DecimalFormat;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-27 11:03:00
 */
public class Data12 extends Data {

    private String Speed;

    public String getDataID() {

        return "0C";
    }

    public String getLength() {
        return "02";
    }

    @JSONField(
            name = "Speed"
    )
    public String getSpeed(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double speed = jsonObject.getDouble("Speed");
        String format = new DecimalFormat("0.0").format(speed);
        String replace = format.replace(".", "");
        String s = HexUtils.intToHex(Integer.valueOf(replace), 4);
        sb.append(s);
        return sb.toString();
    }

    public void setSpeed(String speed) {
        Speed = speed;
    }

    @Override
    public String combine(JSONObject jsonObject) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDataID());
        sb.append(this.getLength());
        sb.append(this.getSpeed(jsonObject));
        return sb.toString();
    }
}
